//
//  HomeViewController.m
//  GPSRecord
//
//  Created by TianWan on 28/02/2017.
//  Copyright © 2017 天玩. All rights reserved.
//

#import "HomeViewController.h"
#import "SettingViewController.h"
@interface HomeViewController ()
{
    NSInteger _alertViewIndex;
}

@property (weak, nonatomic) IBOutlet UIButton *loginButton;


@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self adjustUI];
}


- (void)adjustUI
{
    self.loginButton.layer.cornerRadius = 3.0;
    self.loginButton.clipsToBounds = YES;
}

- (IBAction)login:(id)sender
{
    [ShareSDK getUserInfoWithType:ShareTypeWeixiSession
                      authOptions:nil
                           result:^(BOOL result, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {
                               dispatch_async(dispatch_get_main_queue(), ^{
                                   if (result) {
                                       NSLog(@"%@",[userInfo sourceData]);
                                       NSString *access_token = userInfo.credential.token;
                                       
                                       NSString *openID = [NSString stringWithFormat:@"%@",[userInfo sourceData][@"openid"]];
                                       [[NSUserDefaults standardUserDefaults] setObject:openID forKey:kopenID];
                                       
                                       NSString *nickname = [userInfo sourceData][@"nickname"];
                                       [[NSUserDefaults standardUserDefaults] setObject:nickname forKey:knickname];
                                       
                                       NSString *avatar = [userInfo sourceData][@"headimgurl"];
                                       [[NSUserDefaults standardUserDefaults] setObject:avatar forKey:kavatar];
                                       
                                       SettingViewController *controller = [[SettingViewController alloc] init];
                                       self.view.window.rootViewController = controller;
                                   }else {
                                       [CustomToastView toast:@"获取用户信息失败"];
                                   }
 
                               });
                           }];
}

@end
